uniform vec3 fg; //new color
uniform sampler2D texture; //texture to change
 
void main() {
  vec2 coords = gl_TexCoord[0].xy;
  vec4 normalColor = texture2D(texture, coords).rgba; //original color
  float t = float (normalColor.r + normalColor.g + normalColor.b)/3;
  gl_FragColor = vec4(t, t, t, normalColor.a);
}